package control;

import gui.guiChatBot;

import java.io.IOException;

import matching.SE;
import nlp.NLP;

public class Chatterbot {
	
	boolean isLearning = false;
	boolean first = true;
	String name = "HUMAN";
	String response = "";
	
	public String getName() {
		return name;
	}
	
	public String getAnswer() {
		return response;
	}
	
	public void process(String sen) throws IOException {

		ProcessedInput input = NLP.getInstance().getKeywords(sen);

		if (first) {
			for (String s : input.getListKeyword()) {
				if (!s.toLowerCase().equals("name")) {
					name = s.toUpperCase();
				}
			}
			response = "CHATBOT: " + "nice to meet you, " + name ;
			first = false;
		} else {
			if (isLearning) {
				input.setLearning(true);
				isLearning = false;
			}
			ProcessedOutput answer = SE.getInstance().getAnswers(input);

			if (null != answer) {
				response = "CHATBOT: " + answer.getResponse();
				if (!answer.getExist()) {
					isLearning = true;
				}
			}
		}
	}
	public static void main(String argv[]) {
		guiChatBot gui = new guiChatBot();
		gui.display("Welcome to Chatbot 2013");
		gui.display("CHATBOT: " + "What is your name ?");
	}
}